<?php
/**
 * Created by PhpStorm.
 * User: asus
 * Date: 2017/9/4
 * Time: 13:00
 */

namespace Wechat\Controller;

/*买二手房前台*/
class ErshouController extends CommonController
{
    /*主页*/
    public function index()
    {
        if(IS_POST){
            $post = i('post.');
            /*
            echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> ';
            echo '<pre/>';
            var_dump($post);
            die();
            */
            if(trim(empty($post['name']))) {
                $this->error('请输入姓名');
            }
            if(trim(empty($post['code']))) {
                $this->error('请输入验证码');
            }
            if(!preg_match("/^1[34578]{1}\d{9}$/",$post['tel'])){
                $this->error('手机号格式不正确');
            }
            $data = [
                'type'=>$post['type'],
                'quyu'=>$post['quyu'].$post['jiedao'],
                'fangxing'=>$post['fangxing'],
                'zongjia'=>$post['zongjia'],
                'zhuangxiu'=>$post['zhuangxiu'],
                'mianji'=>$post['mianji'],
                'leibie'=>$post['leibie'],
                'fangling'=>$post['fangling'],
                'name'=>$post['name'],
                'tel'=>$post['tel'],
                'openid'=>$_SESSION['wechatopenid'],
                'time'=>time(),
                'check'=>1,
            ];
            if(M('ershou')->add($data)){
                $this->success('发布成功',U('Wechat/Ershou/index'));
            }else{
                $this->error('发布失败，未知错误！~');
            }
        }else{
            $this->display();
        }
    }
}